import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutterapptest1/ColorsUtils.dart';
import 'package:flutterapptest1/EventBusTest.dart';
import 'package:flutterapptest1/SpUtils.dart';
import 'package:shared_preferences/shared_preferences.dart';

class ThemeModityTest extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _ThemeModityTestState();
  }
}

class _ThemeModityTestState extends State<ThemeModityTest> {
  var _index = -1;
  var eventBus = EventBusTest();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text('主题更换'),
      ),
      body: Center(
        child: Column(
          children: <Widget>[
            GestureDetector(
              onTap: () {
                eventBus.emit("theme", ColorsUtils.colors[0]);
                SpUtils.save("theme", 0);
                setState(() {
                  _index = 0;
                });
              },
              child: Container(
                margin: EdgeInsets.only(top: 15),
                width: 300,
                height: 100,
                decoration: BoxDecoration(
                    border: _index == 0
                        ? Border.all(width: 2.0, color: Colors.black)
                        : null,
                    color: ColorsUtils.colors[0]),
              ),
            ),
            GestureDetector(
              onTap: () {
                eventBus.emit("theme", ColorsUtils.colors[1]);
                SpUtils.save("theme", 1);
                setState(() {
                  _index = 1;
                });
              },
              child: Container(
                margin: EdgeInsets.only(top: 15),
                width: 300,
                height: 100,
                decoration: BoxDecoration(
                    border: _index == 1
                        ? Border.all(width: 2.0, color: Colors.black)
                        : null,
                    color: ColorsUtils.colors[1]),
              ),
            ),
            GestureDetector(
              onTap: () {
                eventBus.emit("theme", ColorsUtils.colors[2]);
                SpUtils.save("theme", 2);
                setState(() {
                  _index = 2;
                });
              },
              child: Container(
                margin: EdgeInsets.only(top: 15),
                width: 300,
                height: 100,
                decoration: BoxDecoration(
                    border: _index == 2
                        ? Border.all(width: 2.0, color: Colors.black)
                        : null,
                    color: ColorsUtils.colors[2]),
              ),
            ),
            GestureDetector(
              onTap: () {
                eventBus.emit("theme", ColorsUtils.colors[3]);
                SpUtils.save("theme", 3);
                setState(() {
                  _index = 3;
                });
              },
              child: Container(
                margin: EdgeInsets.only(top: 15),
                width: 300,
                height: 100,
                decoration: BoxDecoration(
                    border: _index == 3
                        ? Border.all(width: 2.0, color: Colors.black)
                        : null,
                    color: ColorsUtils.colors[3]),
              ),
            ),
            GestureDetector(
              onTap: () {
                eventBus.emit("theme", ColorsUtils.colors[4]);
                SpUtils.save("theme", 4);
                setState(() {
                  _index = 4;
                });
              },
              child: Container(
                margin: EdgeInsets.only(top: 15),
                width: 300,
                height: 100,
                decoration: BoxDecoration(
                    border: _index == 4
                        ? Border.all(width: 2.0, color: Colors.black)
                        : null,
                    color: ColorsUtils.colors[4]),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
